package com.czp.mall.feign.fallbackFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.czp.mall.feign.pojo.Item;
import com.czp.mall.feign.service.ItemServiceFeignHystrixClient;

import feign.hystrix.FallbackFactory;

/**
 * 获取触发hystrix的原因
 * @author chaiz
 *
 */

@Component
public class ItemServiceFeignHystrixClientFallbackFactory implements FallbackFactory<ItemServiceFeignHystrixClient>{

	
	private static final Logger LOGGER = LoggerFactory.getLogger(ItemServiceFeignHystrixClientFallbackFactory.class);
	
	@Override
	public ItemServiceFeignHystrixClient create(Throwable cause) {
		ItemServiceFeignHystrixClientFallbackFactory.LOGGER.error("fallback:"+cause.getStackTrace());	
		ItemServiceFeignHystrixClientFallbackFactory.LOGGER.error("fallback:"+cause.getMessage());	
		
		// TODO Auto-generated method stub
		return new ItemServiceFeignHystrixClient() {
			
			@Override
			public Item queryItemById(Long id) {
				// TODO Auto-generated method stub
				
				return new Item(-1l, cause.getMessage(), null, null, id);
			}
		};
	}

}
